package at.fhooe.engine.physics;

public class SquareBody extends PhysicBody {

	private double m_width;
	private double m_height;
	
	public SquareBody(String name, double width, double height, boolean isEntity) {
		super(name, isEntity);
		m_width = width;
		m_height = height;
	}
	
	public double getWidth() {
		return m_width;
	}
	
	public double getHeight() {
		return m_height;
	}
	@Override
	public boolean isColliding(PhysicBody physicBody) {
		return physicBody.isColliding(this);
	}

	@Override
	public boolean isColliding(CircleBody circleBody) {
		double rectLeft = this.getPositionX();
		double rectRight = this.getPositionX()+this.getWidth();
		double rectTop = this.getPositionY();
		double rectBottom = this.getPositionY() + this.getHeight();
		
		double closestX = Math.max(rectLeft, Math.min(rectRight, circleBody.getPositionX()));
		double closestY = Math.max(rectTop, Math.min(rectBottom, circleBody.getPositionY()));
		
		double distanceX = circleBody.getPositionX() - closestX;
		double distanceY = circleBody.getPositionY() - closestY;
		
		double distanceSquared = distanceX * distanceX + distanceY * distanceY;
		return distanceSquared < (circleBody.getRadius() * circleBody.getRadius());
	}

	@Override
	public boolean isColliding(SquareBody squareBody) {
		// TODO Auto-generated method stub
		return false;
	}

}
